home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / CShell⁄THINK C / DoCursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-20  |  4.8 KB  |  174 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:        CShell
  5. ** File:        docursor.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "CShell.h"                /* Get the CShell includes/typedefs, etc.    */
  19. #include "CShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "CShell.protos"        /* Get the prototypes for CShell.            */
  21.  
  22. #ifndef __TEXTEDITCONTROL__
  23. #include "TextEditControl.h"
  24. #endif
  25.  
  26. #ifndef __TOOLUTILS__
  27. #include <ToolUtils.h>
  28. #endif
  29.  
  30. #ifndef __UTILITIES__
  31. #include "Utilities.h"
  32. #endif
  33.  
  34.  
  35.  
  36. /*****************************************************************************/
  37.  
  38.  
  39.  
  40. RgnHandle    gCurrentCursorRgn;
  41.     /* The current cursor region.  The initial cursor region is an empty
  42.     ** region, which will cause WaitNextEvent to generate a mouse-moved
  43.     ** event, which will cause us to set the cursor for the first time.
  44.     */
  45.  
  46. Cursor    *gCurrentCursor, **gCurrentCursorHndl;
  47.     /* The current cursor that applies to gCurrentCursorRgn.  These values
  48.     ** are here to shorten the re-processing time for determining the
  49.     ** correct cursor after an event.  This is specifically so that characters
  50.     ** can be typed into the TextEdit control faster.  If we spend a great
  51.     ** deal of time per-event recalculating the cursor region, text entry for
  52.     ** the TextEdit control slows down considerably.  If you want to override
  53.     ** the time savings because you are changing the cursor directly, either
  54.     ** set gCurrentCursor to nil, or call DoSetCursor to set the cursor.
  55.     ** DoSetCursor simply sets gCurrentCursor to nil, as well as setting
  56.     ** the cursor.
  57.     */
  58.  
  59.  
  60.  
  61. /*****************************************************************************/
  62. /*****************************************************************************/
  63.  
  64.  
  65.  
  66. /* Handle the cursor changes, based on if an AppleEvent is involved, or
  67. ** depending on the location of the cursor.  This also calculates the region
  68. ** where the current cursor resides (for WaitNextEvent).  If the mouse is
  69. ** ever outside of that region, an event would be generated, causing this
  70. ** function to be called, allowing us to change the region to the region
  71. ** the mouse is currently in.  The only other cursor management in this sample
  72. ** is for operations such as pulling down a menu.  Just prior to pulling down
  73. ** the menu, the arrow cursor is set.  This prevents any latencies in cursor
  74. ** update to cause a non-arrow cursor to be used in the menus.  This technique
  75. ** should be carried throughout the application.
  76. */
  77.  
  78. #pragma segment Main
  79. void    DoCursor(Boolean isAppleEvent, long classID)
  80. {
  81.     WindowPtr        window, oldPort;
  82.     RgnHandle        rgn;
  83.     Rect            outBoxRct, teViewRct;
  84.     Point            mouseLoc;
  85.     short            cursorID;
  86.     TEHandle        outBox, teHndl;
  87.     FileRecHndl        frHndl;
  88.     ControlHandle    viewCtl;
  89.  
  90.     mouseLoc = GetGlobalMouse();
  91.  
  92.     if ((!gInBackground) && (!IsDAWindow(window = FrontWindow()))) {
  93.  
  94.         if (isAppleEvent) {
  95.  
  96.             /* Handle the cursor for Apple Events. */
  97.  
  98.             switch (classID) {
  99.                 case kAEOpenApplication:    cursorID = oappCursor; break;
  100.                 case kAEOpenDocuments:        cursorID = odocCursor; break;
  101.                 case kAEPrintDocuments:        cursorID = pdocCursor; break;
  102.                 case kAEQuitApplication:    cursorID = quitCursor; break;
  103.                 case kAEAnswer:                cursorID = ansrCursor; break;
  104.                 case 'wait':                cursorID = watchCursor; break;
  105.             }
  106.  
  107.             SetRectRgn(gCurrentCursorRgn, kExtremeNeg, kExtremeNeg,
  108.                                           kExtremePos, kExtremePos);
  109.             DoSetCursor(*GetCursor(cursorID));
  110.         }
  111.  
  112.         else {            /* Handle the cursor for non-AppleEvent situations. */
  113.  
  114.             if (IsAppWindow(window)) {
  115.  
  116.                 if (gCurrentCursor) {
  117.                     if (PtInRgn(mouseLoc, gCurrentCursorRgn)) {
  118.                         SetCursor(*gCurrentCursorHndl);
  119.                         return;
  120.                     }
  121.                 }
  122.  
  123.                 frHndl    = (FileRecHndl)GetWRefCon(window);
  124.                 viewCtl   = CTEViewFromTE(outBox = (*frHndl)->doc.outBox);
  125.                 outBoxRct = (*viewCtl)->contrlRect;
  126.  
  127.                 GetPort(&oldPort);
  128.                 SetPort(window);
  129.                 LocalToGlobalRect(&outBoxRct);
  130.                 SetPort(oldPort);
  131.  
  132.                 if (CTETargetInfo(&teHndl, &teViewRct) == window) {
  133.                     if ((teHndl == outBox) && (PtInRect(mouseLoc, &outBoxRct))) {
  134.                         RectRgn(gCurrentCursorRgn, &outBoxRct);
  135.                         SetCursor(*(gCurrentCursorHndl = GetCursor(ibeamCursor)));
  136.                         return;
  137.                     }
  138.                 }
  139.                 SetRectRgn(gCurrentCursorRgn, kExtremeNeg, kExtremeNeg,
  140.                                               kExtremePos, kExtremePos);
  141.                 rgn = NewRgn();
  142.                 RectRgn(rgn, &outBoxRct);
  143.                 DiffRgn(gCurrentCursorRgn, rgn, gCurrentCursorRgn);
  144.                 DisposeRgn(rgn);
  145.             }
  146.  
  147.             DoSetCursor(&QD(arrow));
  148.         }
  149.     }
  150.  
  151.     else {
  152.         SetRectRgn(gCurrentCursorRgn, kExtremeNeg, kExtremeNeg,
  153.                                       kExtremePos, kExtremePos);
  154.         gCurrentCursor = nil;
  155.     }
  156. }
  157.  
  158.  
  159.  
  160. /*****************************************************************************/
  161.  
  162.  
  163.  
  164. #pragma segment Main
  165. void    DoSetCursor(Cursor *cursor)
  166. {
  167.     if (cursor) SetCursor(cursor);
  168.     gCurrentCursor = nil;
  169.     if (!cursor) DoCursor(false, 0);
  170. }
  171.  
  172.  
  173.  
  174.